home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LIFER__ / PROTO / P / PUTILS_L.C < prev    next >
Text File  |  1991-07-23  |  8KB  |  205 lines

  1. /*  PUtils_Life                                                              Utilities
  2.  
  3. File name:  PUtils_Life.C  
  4. Function:  Utilities for the Prototyper specific code.
  5. History: 7/23/91 Original by Prototyper 3.0   */
  6.  
  7.  
  8.  
  9. #include "PCommonLife.h"    /* Common */
  10. #include "Common_Life.h"    /* Common */
  11. #include "PUtils_Life.h"    /* This file */
  12.  
  13. /* ======================================================= */
  14.  
  15. /* Routine: TrapAvailable */
  16. /* Purpose: See if trap is available, non-available traps all have a unique address */
  17.  
  18. Boolean TrapAvailable (trapNumber,tType)                             /* See if a trap is available */
  19. short    trapNumber;
  20. short    tType;
  21. {
  22.         #define UnimplementedTrapNumber     0xA89F                  /* Unimplemented trap number */
  23.         Boolean    theResult;
  24.  
  25.         theResult = (NGetTrapAddress(trapNumber, tType) != GetTrapAddress(UnimplementedTrapNumber));/* Check the two traps */
  26.         return(theResult);
  27. }
  28.  
  29.  
  30. /* ======================================================= */
  31.  
  32. /* Routine: GetUserEvent */
  33. /* Purpose: See if any user events are available */
  34.  
  35. void GetUserEvent(UserEventPRec TheUserEvent)
  36.         UserEventHRec    NextUserEvent;                                  /* The next user event */
  37.  
  38.         TheUserEvent->ID = UserEvent_None;                             /* Set ID to no events are available */
  39.         if (UserEventList != NIL)                                             /* Get first entry in the list */
  40.             {
  41.                 HLock((Handle)UserEventList);                               /* Lock for safety */
  42.                 TheUserEvent->ID = (*UserEventList)->ID;                 /* The event ID */
  43.                 TheUserEvent->ID2 = (*UserEventList)->ID2;             /* The optional ID */
  44.                 TheUserEvent->Data1 = (*UserEventList)->Data1;/* The optional data */
  45.                 TheUserEvent->Data2 = (*UserEventList)->Data2;/* The optional data */
  46.                 TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
  47.                 NextUserEvent = (*UserEventList)->Next;                 /* The next list */
  48.  
  49.                 DisposHandle((Handle)UserEventList);                       /* Remove this list item */
  50.                 UserEventList = NextUserEvent;                             /* Make the next item the new first item */
  51.             }
  52. }
  53.  
  54.  
  55. /* ======================================================= */
  56.  
  57. /* Routine: Add_UserEvent */
  58. /* Purpose: Add a user event */
  59.  
  60. void Add_UserEvent( ID,  ID2, Data1, Data2,  theHandle)
  61. short        ID;
  62. short        ID2;
  63. long        Data1;
  64. long        Data2;
  65. Handle    theHandle;
  66.         UserEventHRec    NewUserEvent;                                   /* The new user event */
  67.         UserEventHRec    theUserEvent;                                    /* The user event */
  68.  
  69.         NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
  70.         if (NewUserEvent != NIL)                                             /* Only do if we got the new record */
  71.             {
  72.                 HLock((Handle)NewUserEvent);                               /* Lock for safety */
  73.                 (*NewUserEvent)->ID = ID;                                   /* The event ID */
  74.                 (*NewUserEvent)->ID2 = ID2;                                /* The optional ID */
  75.                 (*NewUserEvent)->Data1 = Data1;                          /* The optional data */
  76.                 (*NewUserEvent)->Data2 = Data2;                          /* The optional data */
  77.                 (*NewUserEvent)->theHandle = theHandle;                 /* The optional handle */
  78.                 (*NewUserEvent)->Next = NIL;                              /* No next item after this one */
  79.  
  80.                 if (UserEventList == NIL)                                      /* See if anyone is in the list yet */
  81.                     UserEventList = NewUserEvent;                          /* Make this one the first in the list */
  82.                 else                                                               /* Not the first in the list */
  83.                     {
  84.                         theUserEvent = UserEventList;                         /* Get the first one */
  85.                         while ((*theUserEvent)->Next != NIL)                 /* Get the next one */
  86.                         {
  87.                                 theUserEvent = (*theUserEvent)->Next;
  88.                         }
  89.                         (*theUserEvent)->Next = NewUserEvent;            /* Tack on to the end */
  90.                     }
  91.             }
  92. }
  93.  
  94. /* ======================================================= */
  95.  
  96.  
  97. /* This is a routine used to get a string from a TE area, limited to 250 characters */
  98. void Get_TE_String( theTEArea, theString)
  99. TEHandle        theTEArea;
  100. Str255    *theString;
  101.         short Index;                                                            /* Use to loop thru the characters */
  102.         short TitleLength;                                                     /* Number of characters to do */
  103.         CharsHandle theCharsHandle;                                        /* Used to get global edit text */
  104.         Ptr theStringPtr;                                                     /* Pointer to the string, byte level */
  105.  
  106.         theCharsHandle = TEGetText(theTEArea);                         /* Get the character handle */
  107.         HLock((Handle)theCharsHandle);                                    /* Lock it for safety */
  108.         TitleLength = (*theTEArea)->teLength;                            /* Get the number of characters */
  109.          *theString[0] = 0;                                                   /* Start with an empty string */
  110.         if (TitleLength > 0) 
  111.             {
  112.                 theStringPtr = (Ptr)((long)theString + (long)1);          /* Start of the string data */
  113.                 if (TitleLength > 250) 
  114.                     TitleLength = 250;
  115.                 for (Index = 0; Index < TitleLength; Index++)
  116.                     *theStringPtr++ = (char)(*theCharsHandle)[Index];
  117.                 *theString[0] = TitleLength;
  118.             }
  119. }
  120.  
  121. /* ======================================================= */
  122.  
  123.  
  124. /* This is a routine used to create a TE area */
  125. void Make_TE_Area(theTEArea, Position, theFontSize, theFont, DefaultStringID)
  126. TEHandle        *theTEArea;
  127. Rect    *Position;
  128. short        theFontSize;
  129. short        theFont;
  130. short        DefaultStringID;
  131. {
  132.         FontInfo    ThisFontInfo;                                              /* Use to get the font data */
  133.  
  134.         TextSize(theFontSize);                                               /* Set the size */
  135.         TextFont(theFont);                                                    /* Set the font */
  136.         GetFontInfo(&ThisFontInfo);                                         /* Get Ascent height for positioning */
  137.         TextSize(12);                                                         /* Restore the size */
  138.         TextFont(applFont);                                                   /* Restore the font */
  139.  
  140.         tempRect = *Position;                                                /* Get the rect */
  141.         FrameRect(&tempRect);                                             /* Frame this TE area */
  142.         InsetRect(&tempRect, 3, 3);                                        /* Indent for TE inside of box */
  143.          *theTEArea = TENew(&tempRect, &tempRect);                 /* Create the TE area */
  144.         if (theInput != NIL)                                                     /* See if there is already a TE area */
  145.             TEDeactivate(theInput);                                           /* Yes, so turn it off */
  146.         theInput = *theTEArea;                                              /* Activate the TE area */
  147.         HLock((Handle)*theTEArea);                                        /* Lock the handle before using it */
  148.         (**theTEArea)->txFont = theFont;                                 /* Font to use for the TE area */
  149.         (**theTEArea)->fontAscent = ThisFontInfo.ascent;             /* Font ascent */
  150.         (**theTEArea)->lineHeight = ThisFontInfo.ascent + ThisFontInfo.descent + ThisFontInfo.leading;/* Font ascent + descent + leading */
  151.         HUnlock((Handle)*theTEArea);                                     /* UnLock the handle when done */
  152.         GetIndString(sTemp, DefaultStringID, 1);                         /* Get the default string */
  153.         TESetText(&sTemp[1], sTemp[0], theInput);                     /* Place default text in the TE area */
  154.         TEActivate(theInput);                                                 /* Make the TE area active */
  155. }
  156.  
  157. /* ======================================================= */
  158.  
  159.  
  160. /* Setup a dialog or alert item */ 
  161. void SetupTheItem( theDialog, ItemID, SizeIt, ShowIt,EnableIt,SetTheMax,thePosition, ExtraData, StringID)
  162. DialogPtr    theDialog;
  163. short        ItemID;
  164. Boolean        SizeIt;
  165. Boolean        ShowIt;
  166. Boolean        EnableIt;
  167. Boolean        SetTheMax;
  168. Rect        *thePosition;
  169. long        ExtraData;
  170. short        StringID;
  171. {
  172.         Rect        tempRect;                                                  /* Temporary rectangle */
  173.         short    DType;                                                         /* Type of dialog item */
  174.         Handle    DItem;                                                        /* Handle to the dialog item */
  175.         ControlHandle    CItem;                                               /* Control handle */
  176.  
  177.         GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);/* Get the item handle and size */
  178.         CItem = (ControlHandle)DItem;                                     /* Change to control handle */
  179.         if (SizeIt)                                                               /* Have to resize all CDEF connected controls */
  180.             SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  181.         *thePosition = tempRect;                                            /* Pass back the zone location and size */
  182.         if (ExtraData != NIL)                                                  /* See if extra data for a CDEF */
  183.             (*CItem)->contrlData = (Handle)ExtraData;                   /* Send it */
  184.         if (StringID != 0)                                                      /* See if a CDEF and needs the title set again*/
  185.             {
  186.                 GetIndString(sTemp,StringID,1);                             /* Get the string */
  187.                 SetCTitle(CItem,sTemp);                                      /* Set the string */
  188.             }
  189.         if (EnableIt)                                                             /* See if enable or disable the zone */
  190.             HiliteControl (CItem,0);                                          /* Enable the zone */
  191.         else
  192.             HiliteControl (CItem,255);                                       /* Dim the zone */
  193.         if (SetTheMax)
  194.             SetCtlMax(CItem,12345);                                        /* Set the flag to the CDEF */
  195.         if (ShowIt)
  196.             ShowControl(CItem);                                              /* Show it to activate it */
  197.  
  198. }
  199.  
  200. /* ======================================================= */
  201.  
  202.